package practise;

import static org.junit.Assert.assertTrue;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import org.junit.Before;
import org.junit.Test;


public class CenterRepositoryTest {
	
	@Before
	public void setUp() {
		System.setProperty("junittesting", "true");
		purge();
	}

	@Test
	public void addCenterTest() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest2() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest3() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest4() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest5() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest6() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest7() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest8() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest9() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest10() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest11() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest12() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest13() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest14() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest15() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest16() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest17() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest18() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest19() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest20() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest21() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest22() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest23() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest24() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	@Test
	public void addCenterTest25() {
		CenterRepository.add("teSt");
		
		Center center = CenterRepository.get("test");
		assertTrue(center != null);
		assertTrue(center.name.equals("test"));
	}
	
	
	
	private static void purge() {
									
		try {
			String sql = "delete from centers";			
			
			try (Connection connection = DriverManager.getConnection(Utils.getCloudSqlURL())) {
				
				try (PreparedStatement ps = connection.prepareStatement(sql)) {									
					
					ps.executeUpdate();					
				}
			}									
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		}		
	}
}
